using System;

namespace Yaml.Utilities {
    /// <summary>
    /// Utility class that is used for checking runtime conditions in code
    /// </summary>
    public static class Requires {
        /// <summary>
        /// Throws an ArguementNullException if the given argument is null
        /// </summary>
        public static void NotNull(object argument) {
            if (argument == null) {
                throw new ArgumentNullException();
            }
        }
        /// <summary>
        /// Throws an ArguementNullException if the given argument is null
        /// </summary>
        public static void NotNull(object argument, string argumentName) {
            if (argument == null) {
                throw new ArgumentNullException(argumentName);
            }
        }
        /// <summary>
        /// Throws an ArguementNullException if the given argument is null
        /// </summary>
        public static void NotNull(object argument, string argumentName, string message) {
            if (argument == null) {
                throw new ArgumentNullException(argumentName, message);
            }
        }
        /// <summary>
        /// Throws an ArguementException if the given condition is false
        /// </summary>
        public static void That(bool condition) {
            if (!condition) {
                throw new ArgumentException();
            }
        }
        /// <summary>
        /// Throws an ArguementException if the given condition is false
        /// </summary>
        public static void That(bool condition, string message) {
            if (!condition) {
                throw new ArgumentException(message);
            }
        }
        /// <summary>
        /// Throws an ArguementException if the given condition is false
        /// </summary>
        public static void That(bool condition, string message, string argumentName) {
            if (!condition) {
                throw new ArgumentException(message, argumentName);
            }
        }
        /// <summary>
        /// Throws an ArguementException if all the given conditions are false
        /// </summary>
        public static void AnyOf(params bool[] conditions) {
            foreach (bool condition in conditions) {
                if (condition) { return; }
            }
            throw new ArgumentException();
        }
        /// <summary>
        /// Throws an ArguementException if all the given conditions are false
        /// </summary>
        public static void AnyOf(string message, params bool[] conditions) {
            foreach (bool condition in conditions) {
                if (condition) { return; }
            }
            throw new ArgumentException(message);
        }
        /// <summary>
        /// Throws an ArguementException if all the given conditions are false
        /// </summary>
        public static void AnyOf(string message, string argumentName, params bool[] conditions) {
            foreach (bool condition in conditions) {
                if (condition) { return; }
            }
            throw new ArgumentException(message, argumentName);
        }
        /// <summary>
        /// Throws an ArguementException if any of the given conditions are false
        /// </summary>
        public static void AllOf(string message, string argumentName, params bool[] conditions) {
            foreach (bool condition in conditions) {
                if (!condition) { throw new ArgumentException(message, argumentName); }
            }            
        }
        /// <summary>
        /// Throws an ArguementException if any of the given conditions are false
        /// </summary>
        public static void AllOf(string message, params bool[] conditions) {
            foreach (bool condition in conditions) {
                if (!condition) { throw new ArgumentException(message); }
            }
        }
        /// <summary>
        /// Throws an ArguementException if any of the given conditions are false
        /// </summary>
        public static void AllOf(params bool[] conditions) {
            foreach (bool condition in conditions) {
                if (!condition) { throw new ArgumentException(); }
            }
        }
    }
}